package com.his.controller;


import com.his.entity.Department;
import com.his.entity.ResponseResult;
import com.his.entity.User;
import com.his.service.IDepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 科室表(done) 前端控制器
 * </p>
 *
 * @author Demoon Liu
 * @since 2022-02-20
 */
@RestController
@RequestMapping("/department")
@Tag(name = "科室管理模块接口")
public class DepartmentController {

    @Resource
    private IDepartmentService service;

    @PostMapping("/insert")
    @PreAuthorize("hasAuthority('administer')")
    @Operation(summary = "新增科室", description = "需要管理员权限，catid，code，name是必需参数")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，插入成功"),
            @ApiResponse(responseCode = "400", description = "返回400，插入失败"),
    })
    public ResponseResult insert(@RequestBody Department department) {
        return service.myInsert(department);
    }

    @PostMapping("update")
    @PreAuthorize("hasAuthority('administer')")
    @Operation(summary = "根据id更新科室信息", description = "需要管理员权限，id是必要参数")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，更新成功"),
            @ApiResponse(responseCode = "400", description = "返回400，更新失败"),
    })
    public ResponseResult update(@RequestBody Department department) {
        return service.myUpdate(department);
    }

    @PostMapping("searchAll")
    @Operation(summary = "获取所有科室信息")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，查询成功和所有科室信息"),
            @ApiResponse(responseCode = "400", description = "返回400，查询失败"),
    })
    public ResponseResult searchAll() {
        return service.mySearchAll();
    }

    @PostMapping("fuzzySearch")
    @Operation(summary = "模糊查询科室信息", description = "字符串是参数，注意是Post，参数在body里")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，模糊查询成功和科室信息"),
            @ApiResponse(responseCode = "400", description = "返回400，模糊查询失败"),
    })
    public ResponseResult fuzzySearch(@RequestBody String str) {
        return service.myFuzzySearch(str);
    }

    @PostMapping("delete")
    @PreAuthorize("hasAuthority('administer')")
    @Operation(summary = "根据id删除科室信息", description = "需要管理员权限，id是必要参数")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，删除成功"),
            @ApiResponse(responseCode = "400", description = "返回400，删除失败"),
    })
    public ResponseResult delete(@RequestBody Department department) {
        return service.myDelete(department);
    }
}
